'use strict';

angular.module('myApp.students_detail', [])

.controller('students_detailCtrl', ['$scope','$routeParams','$http',    
    function($scope,$routeParams,$http,$location) {
        $http.get('v1/student/'+ $routeParams.id).success(function(data){
            $scope.student = data.message['data'][0];
              console.log($scope.student);
        });

        //清空 提交
        $scope.submit = function(student){ 

            student.classes_name = $("#sclass option:selected").attr('label');
            student.school = $("#sschool option:selected").attr('label');

            $scope.tem = angular.copy(student);
             console.log( $scope.tem);
            $http.put('v1/student/'+ $routeParams.id,$scope.tem).success(function(data){

                if( !data.error ){
                    alert("修改成功","success");
                    window.location.href = '#/students';
                }else{
                    alert(data.message);
                }
            });
        };

        // 日历
        $('.form-date').datetimepicker(
        {
            language:  'zh-CN',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0,
            format: 'yyyy-mm-dd'
        });
}]);